//
//  NetBusinessUser_GetCategoryList.m
//  EpointFrame5
//
//  Created by 李亚春 on 14-3-7.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "NetBusinessUser_GetCategoryList.h"
#import "CateGoryInfoModel.h"

@implementation NetBusinessUser_GetCategoryList

-(void)execute
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *ValidateData = [EpointBizTools getToken];
    NSString *url = self.getMobileOAWebserviceURL;
    NSString *wsNamespace = NSLocalizedString(@"Epoint_DNet_WS_NameSpace", @"");
    NSString *userguid = [params objectForKey:@"OwnerUserGuid"];
    NSString *ParentCategoryGuid = [params objectForKey:@"ParentCategoryGuid"];
    
    NSString *ParasXml = @"<![CDATA[<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><OwnerUserGuid>%@</OwnerUserGuid><ParentCategoryGuid>%@</ParentCategoryGuid></paras>]]>";
    ParasXml = [NSString stringWithFormat:ParasXml,userguid,ParentCategoryGuid];
    EpointWebServiceUtil *ws = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:@"NetBusinessUser_GetCategoryList"];
    [ws addParameterForString:@"ValidateData" value:ValidateData];
    [ws addParameterForString:@"ParasXml" value:ParasXml];
    NSString *bs =  ws.start;
    if ([self validateXMLWS:bs]) {
        [self exeSuccessWithData:[self getList:bs]];
    }
}

-(NSMutableArray*)getList:(NSString*)_xml{
    NSString *xmldata = [EpointStringUtil getXMLFormatedAttributeBsWithTag:_xml xmlTag:@"CateGoryList"];
    GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithXMLString:xmldata  options:0 error:nil];
    GDataXMLElement *rootElement = [doc rootElement];
    NSArray *arrays = [rootElement elementsForName:@"CateGoryInfo"];
    NSMutableArray *listmp = [[NSMutableArray alloc]init];
    
    for (GDataXMLElement *arr in arrays)
    {
        CateGoryInfoModel *m = [[CateGoryInfoModel alloc]init];
        GDataXMLElement *CateGoryGuid = [[arr elementsForName:@"CateGoryGuid"] objectAtIndex:0];
        m.CateGoryGuid = [CateGoryGuid stringValue];
        
        GDataXMLElement *CateGoryName = [[arr elementsForName:@"CateGoryName"] objectAtIndex:0];
        m.CateGoryName = [CateGoryName stringValue];
        
        GDataXMLElement *OrderNumber = [[arr elementsForName:@"OrderNumber"] objectAtIndex:0];
        m.OrderNumber = [OrderNumber stringValue];
        m.type=@"ou";
        [listmp addObject:m];
    }
    return listmp;
}

@end
